package com.rmb.util;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.rmb.dao.TaskInfoDao;
import com.rmb.entity.TaskInfo;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

/**
 * @version 1.0
 * @Author a
 * @Date 2021/1/8 19:40
 */
public class Writwe {
    @Autowired
    TaskInfoDao taskDao;

    /**
     * mysql导入Excel
     * @param dizhi
     * @throws IOException
     */
    private void writeExport(String dizhi) throws IOException {
        //获取数据
        List<TaskInfo> all = taskDao.findAll();
        //导出Excel
        //参数1：exportParams导出配置对象，参数2：导出的类型 参数3：导出数据集合
        Workbook wb = ExcelExportUtil.exportExcel(new ExportParams("任务设计列表", "任务设计"), TaskInfo.class, all);
        //将Excel写入指定位置
        FileOutputStream outputStream = new FileOutputStream(dizhi);
        wb.write(outputStream);
        outputStream.close();
    }
}
